﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace GridViewLogoin
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            FillData();
        }

        private void FillData()
        {
            var sql = "select * from StuInfo where IsActive = 1";
            var dt = DbHelper.GetData(sql);

            gv1.DataSource = dt;
            gv1.DataBind();
        }

        protected void Unnamed_RowEditing(object sender, GridViewEditEventArgs e)
        {
            gv1.EditIndex = e.NewEditIndex;
            FillData();
        }

        protected void Unnamed_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            var Id = getCellValue(e.RowIndex, 0);
            var StuName = getCellValue(e.RowIndex, 1);
            var StuNo = getCellValue(e.RowIndex, 2);
            var StuSex = getCellValue(e.RowIndex, 3);
            var Remarks = getCellValue(e.RowIndex, 4);
        }

        private object getCellValue(int RowIndex, int CellIndex)
        {
            var getIndex = gv1.Rows[RowIndex].Cells[CellIndex];

            var str = getIndex.Controls.Count > 0 ? ((TextBox)getIndex.Controls[0]).Text.ToString() : getIndex.Text;

            return str;
        }

        protected void Unnamed_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {

        }

        protected void Unnamed_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {

        }

        protected void Unnamed1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}